package com.scgl.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.order.domain.ScglWork;
import com.scgl.order.service.IScglWorkService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 关联工单Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/work")
public class ScglWorkController extends BaseController
{
    @Autowired
    private IScglWorkService scglWorkService;

    /**
     * 查询关联工单列表
     */
    @RequiresPermissions("order:work:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglWork scglWork)
    {
        startPage();
        List<ScglWork> list = scglWorkService.selectScglWorkList(scglWork);
        return getDataTable(list);
    }

    /**
     * 导出关联工单列表
     */
    @RequiresPermissions("order:work:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglWork scglWork)
    {
        List<ScglWork> list = scglWorkService.selectScglWorkList(scglWork);
        ExcelUtil<ScglWork> util = new ExcelUtil<ScglWork>(ScglWork.class);
        util.exportExcel(response, list, "关联工单数据");
    }

    /**
     * 获取关联工单详细信息
     */
    @RequiresPermissions("order:work:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scglWorkService.selectScglWorkById(id));
    }

    /**
     * 新增关联工单
     */
    @RequiresPermissions("order:work:add")
    @Log(title = "关联工单新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglWork scglWork)
    {
        return toAjax(scglWorkService.insertScglWork(scglWork));
    }

    /**
     * 修改关联工单
     */
    @RequiresPermissions("order:work:edit")
    @Log(title = "关联工单修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglWork scglWork)
    {
        return toAjax(scglWorkService.updateScglWork(scglWork));
    }

    /**
     * 删除关联工单
     */
    @RequiresPermissions("order:work:remove")
    @Log(title = "关联工单删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scglWorkService.deleteScglWorkByIds(ids));
    }
}
